package com.share.schedule.quartz.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.share.common.common.Page;
import com.share.common.common.Result;
import com.share.schedule.quartz.domain.SysJobLog;
import com.share.schedule.quartz.service.ISysJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 调度日志操作处理
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController {
    @Autowired
    private ISysJobLogService jobLogService;

    /**
     * 查询定时任务调度日志列表
     */

    @GetMapping("/list")
    public Page<SysJobLog> list(SysJobLog req) {
        PageHelper.startPage(req.getPageNum(), req.getPageSize());
        List<SysJobLog> list = jobLogService.selectJobLogList(req);
        return new Page<>(list, new PageInfo<>(list).getTotal(), req);
    }

    /**
     * 根据调度编号获取详细信息
     */

    @GetMapping(value = "/{jobLogId}")
    public Result getInfo(@PathVariable Long jobLogId) {
        return Result.success(jobLogService.selectJobLogById(jobLogId));
    }


    /**
     * 删除定时任务调度日志
     */

    @DeleteMapping("/{jobLogIds}")
    public Result remove(@PathVariable Long[] jobLogIds) {
        return Result.success(jobLogService.deleteJobLogByIds(jobLogIds));
    }

    /**
     * 清空定时任务调度日志
     */
    @DeleteMapping("/clean")
    public Result clean() {
        jobLogService.cleanJobLog();
        return Result.success();
    }
}
